package com.fanghuaiming.seata.item.service.impl;

import com.fanghuaiming.seata.item.dao.mapper.SeataTccSkuMapper;
import com.fanghuaiming.seata.item.service.ItemService;
import com.fanghuaiming.seata.item.tcc.SeataPhaseTccItem;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/****
 * @description: 商品服务接口实现类
 * @version:1.0.0
 * @author fanghuaiming
 * @data Created in 2020/11/27 下午1:59
 *
 */
@Service
@Slf4j
public class ItemServiceImpl implements ItemService {

    /**
     * 商品mapper
     */
    @Autowired
    private SeataTccSkuMapper seataTccSkuMapper;

    /**
     * 商品库存TCC组件
     */
    @Autowired
    private SeataPhaseTccItem seataPhaseTccItem;

    /**
     * @Description: 扣减商品库存
     *
     * @param:
     * @return:
     * @auther: fanghuaiming
     * @date: 2020/11/30 下午5:44
     * @version:1.0.0
     */
    @SuppressWarnings("all")
    @GlobalTransactional
    @Override
    public void decrease(Long productId, Integer count) {
        //seataTccSkuMapper.decrease(productId,count);
        //调用TCC的第一阶段方法
        seataPhaseTccItem.prepareDecreaseItem(null,productId,count);
    }

}
